//
//  WQCTabBar.swift
//  3-微博
//
//  Created by DDDD on 16/2/24.
//  Copyright © 2016年 gongsimingzi. All rights reserved.
//

import UIKit

class WQCTabBar: UITabBar {

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
//  重新init 方法
    override init(frame:CGRect){
        super.init(frame:frame)
        setupUI()
    
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置 UI 界面
    func setupUI(){
        addSubview(composeButton)
    }
    //懒加载
    lazy var composeButton:UIButton = {
        //创建 button
        let button = UIButton(type: UIButtonType.Custom)
        //设置 button 背景图片:点击,正常状态
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        //设置大小
        button.sizeToFit()
        
        return button
    }()
    override func layoutSubviews() {
        super.layoutSubviews()
        
        var index = 0
        let width = bounds.width / 5
        let height = bounds.height
        
        for subview in subviews{
        
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
            subview.frame = CGRectMake(CGFloat(index++) * width, 0, width, height)
                if index == 2{ index++}
            }
            
        }
        composeButton.frame = CGRectMake(2 * width, 0, width, height)
        
    }

}
